package com.fanshe.demo03;

import java.lang.reflect.Constructor;

public class Demo01 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
      /*  Constructor<?>[] getConstructors() 返回所有公共构造方法对象的数 组
        Constructor<?>[] getDeclaredConstructors() 返回所有构造方法对象的数组
        Constructor getConstructor(Class<?>... parameterTypes) 返回单个公共构造方法对象
        Constructor getDeclaredConstructor(Class<?>... parameterTypes) 返回单个构造方法对象*/
        //method01();
        //method02();
        //method03();
        Class aClass = Class.forName("com.fanshe.demo03.Student");
        Constructor declaredConstructor = aClass.getDeclaredConstructor(String.class);
        System.out.println(declaredConstructor);

    }

    private static void method03() throws ClassNotFoundException, NoSuchMethodException {
        Class aClass = Class.forName("com.fanshe.demo03.Student");
        Constructor constructor = aClass.getConstructor();
        System.out.println(constructor);

        Constructor constructor1 = aClass.getConstructor(String.class, int.class);
        System.out.println(constructor1);

        Constructor constructor2 = aClass.getConstructor(int.class);
        System.out.println(constructor2);
    }

    private static void method02() throws ClassNotFoundException {
        Class aClass = Class.forName("com.fanshe.demo03.Student");
        Constructor[] constructors = aClass.getDeclaredConstructors();
        for (Constructor constructor : constructors) {
            System.out.println(constructor);
        }
    }

    //Constructor<?>[] getConstructors() 返回所有公共构造方法对象的数 组
    private static void method01() throws ClassNotFoundException {
        Class aClass = Class.forName("com.fanshe.demo03.Student");
        Constructor[] constructors = aClass.getConstructors();
        for (Constructor constructor : constructors) {
            System.out.println(constructor);
        }
    }
}
